﻿using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.Framework.Reflection;
using Pixysoft.Weblications.Sango.Dao;
using Pixysoft.Weblications.Sango.Formular;
using Pixysoft.Weblications.Sango.Protocol.player;
using Pixysoft.Weblications.Sango.Protocol;

namespace Pixysoft.Weblications.Sango.Command.party
{
    partial class SangoPartyHandler
    {
        public party_logoupgrade party_logoupgrade()
        {
            string userCode = SangoManager.Authentication();

            party_logoupgrade response = ReflectionManager.CreatePojo<party_logoupgrade>();
            response.Succeed = false;

            Entities.Usr_Profile profile = UsrProfileDao.getUsrProfile(userCode);

            Entities.Usr_Party party = PartyDao.tryGetPartyByUsercode(userCode);

            if (party == null)
            {
                response.Message = "没有加入军团";
                return response;
            }

            if (party.Logolevel >= PartyFormular.default_maxlogolevel)
            {
                response.Message = "团徽到达最大等级";
                return response;
            }

            long goldvalue = PartyFormular.LogoLevelGoldValue(party.Logolevel + 1);

            if (!UsrProfileDao.tryDecreaseGoldValue(profile, goldvalue))
            {
                response.Message = "金币不足";
                return response;
            }

            IEntityNoebeTransaction command = SettingHelper.EntityTransaction;

            command.Begin(delegate()
            {
                PartyDao.logoLevelup(party);

                command.Update(party);

                command.Update(profile);

                command.Commit();
            });

            response.profile = UsrProfileFacade.ToProfile(profile);
            response.Succeed = true;
            return response;
        }


    }
    public interface party_logoupgrade : ISangoResponse
    {
        player_profile profile { get;set;}

    }
}
